fqs_p <- function (fqs='fqs', nam='name') {
# xy=read.csv(fil, header=F)
# xy1=as.vector(xy, mode='numeric')
# len=length(xy1)

# x0=94
# y0=44

# x1_zeiss=-142.7
# y1_zeiss=-15.3





# if (xy1[1] < 70) {
# y=xy1[seq(1,len,2)]-y0
# x=xy1[seq(2,len,2)]-x0
# }else {
# x=xy1[seq(1,len,2)]-x0
# y=xy1[seq(2,len,2)]-y0
# }

# trans=1000
# x_zeiss=(x1_zeiss + x)* trans
# y_zeiss=(y1_zeiss - y)* trans

len=nrow(fqs)

xlim=c(0,(nrow(fqs)+1))
ylim=c(-2,45)
# lin=seq(xlim[1]+1, xlim[2]-1)

plot(NA, type='n', xlim=xlim, ylim=ylim, cex.axis=.5)
# abline(h=lin, v=lin, col='gray')
# lines(c(0, 15, 15, 0, 0), c(0, 0, 15, 15, 0))
# points(x, y, xlim=xlim, ylim=xlim, asp=1, pch=16)


# lenx=length(x)
# xy_str="#,X,Y: "
# for ( i in 1:lenx) {
# xys=paste(i, x_zeiss[i], y_zeiss[i], sep=',')
# xy_str=paste(xy_str, xys, sep='\n')
# }
# text(x, y, 1:lenx, pos=4)
# title(nam, xlab=xy_str)

# }

title_main=paste("Quality Scores for ", nam)

title(main=title_main, xlab="Read position", ylab="Quality score")



width=.3
width1=.1

for (i in 1:nrow(fqs)) {

lines(c(i-width, i+width, i+width, i-width, i-width), c(fqs$Q1[i], fqs$Q1[i], fqs$Q3[i], fqs$Q3[i], fqs$Q1[i]), col='gray')

lines(c(i-width1, i+width1), c(fqs$rW[i], fqs$rW[i]), col='gray')

lines(c(i-width1, i+width1), c(fqs$lW[i], fqs$lW[i]), col='gray')
lines(c(i, i), c(fqs$lW[i], fqs$Q1[i]), col='gray')
lines(c(i, i), c(fqs$rW[i], fqs$Q3[i]), col='gray')

lines(c(i-width1, i+width1), c(fqs$med[i], fqs$med[i]), col='red')

}


ylim=c(0,1)
plot(NA, type='n', xlim=xlim, ylim=ylim, cex.axis=.5)

title_main=paste("Nucleotides distribution for ", nam)

title(main=title_main, xlab="Read position", ylab="Percent of total")

cols=c('red', 'green', 'blue', 'yellow')
nts=c('A','C','G','T')



for (i in 1:nrow(fqs)) {

a=fqs$A_Count[i]/fqs$count[i]
b=(fqs$A_Count[i]+fqs$C_Count[i])/fqs$count[i]
c1=(fqs$A_Count[i]+fqs$C_Count[i]+fqs$G_Count[i])/fqs$count[i]
d=(fqs$A_Count[i]+fqs$C_Count[i]+fqs$G_Count[i]+fqs$T_Count[i])/fqs$count[i]

lines(c(i-width, i+width, i+width, i-width, i-width), c(0, 0, a, a, 0), col=cols[1])
lines(c(i-width, i+width, i+width, i-width, i-width), c(a, a, b, b, a),col=cols[2])
lines(c(i-width, i+width, i+width, i-width, i-width), c(b, b, c1, c1, b),col=cols[3])
lines(c(i-width, i+width, i+width, i-width, i-width), c(c1, c1, d, d, c1),col=cols[4])

}

# legend("topleft", inset=.05, lty=rep(1, length(nts)), nts, col=cols, text.col=cols, box.col='white', bg='white', density=)

axis(4, at=seq(.125,by=.25, length.out=4), labels=nts,tick=F, line=-1)


# plot(NA, type='n', xlim=xlim, ylim=ylim, cex.axis=.5)

ylim=c(0, 1.05*fqs$count[1])

plot(fqs$column, fqs$count, xlim=xlim, ylim=ylim, type='l', cex.axis=.5, col='blue')

title_main=paste("Nucleotide count for ", nam)

title(main=title_main, xlab="Reads position", ylab="Nucleotide count")





r_len=fqs$count[1:(len-1)]-fqs$count[2:len]
r_len[len]=fqs$count[len]

plot(r_len, type='h', xlim=xlim, ylim=ylim, cex.axis=.5, col='blue')

title_main=paste("Frequency of read length for ", nam)

title(main=title_main, xlab="Length of reads", ylab="Frequency")


}

